import "../../less/talking/talking.less";

var num = sessionStorage.getItem("name");

var strnNum = 0;

var name = "";

var me1 = $(".me1");
var fake1 = $(".fake1");
var fake2 = $(".fake2");
var select = $(".select");
var selectA = $(".selectA");
var selectB = $(".selectB");
var me2Img = $(".me2-img");
var fake1Img = $(".fake1-img");
var fake2Img = $(".fake2-img");
var me1Img = $(".me1-img");
var videoDialog = $(".video-dialog");

setInterval(function () {
  strnNum++;
  if (strnNum == 1) {
    me1.show();
  }
  if (strnNum == 2) {
    fake1.show();
  }
  if (strnNum == 3) {
    select.show();
    clearInterval();
  }
}, 1000);

var talkingBox = $(".talking-box");

switch (num) {
  case "2":
    name = "卜";
    break;
  case "3":
    name = "苟";
    break;
  case "4":
    name = "贾";
    break;
  default:
    name = "吴";
    break;
}
var src = `../../image/3/${name}.jpg`;
var m1Src = `./image/3/${name}医生聊天/me1.png`;
var fake1Src = `./image/3/${name}医生聊天/fake1.png`;
var fake2Src = `./image/3/${name}医生聊天/fake2.png`;
var selectASrc = `./image/3/${name}医生聊天/a.png`;
var selectBSrc = `./image/3/${name}医生聊天/b.png`;

me1Img.attr("src", m1Src);
fake1Img.attr("src", fake1Src);
fake2Img.attr("src", fake2Src);
selectA.attr("src", selectASrc);
selectB.attr("src", selectBSrc);
talkingBox.css("background-image", `url(${src})`);

selectA.click(function () {
  me2Img.attr("src", `./image/3/${name}医生聊天/me2a.png`);
  $(".me2").show();
  hideSelect();
});

selectB.click(function () {
  me2Img.attr("src", `./image/3/${name}医生聊天/me2b.png`);
  $(".me2").show();
  hideSelect();
});

var hideSelect = function () {
  select.addClass("selectHide");
  let videoNum = 0;

  setInterval(function () {
    videoNum++;
    fake2.show();
    if (videoNum == 3 && (num == 2 || num == 3)) {
      videoDialog.show();
      setTimeout(function () {
        $(".phone-img").css("animation-name", "buzz-out");
        $(".phone-img").css("animation-duration", "1s");
        $(".phone-img").css("animation-iteration-count", "infinite");
        $(".hand-img").show();
      }, 500);
      clearInterval();
    }
    if (videoNum == 3 && (num == 1 || num == 4)) {
      $(".over-box-dialog").show();
      $(".down-dialog").show();
    }
  }, 1000);
  // select.hide();
};
$(".trueBtn").on("click", function () {
  linkTo("/doctor");
});

$(".okVideo").click(function () {
  videoDialog.hide();
  $(".video-yuan").show();
  window.globalClose();
  $(".videoBox").get(0).play();
  document.addEventListener(
    "WeixinJSBridgeReady",
    function () {
      $(".videoBox").get(0).play();
    },
    false
  );
  $(".text-talking ").show();
  var elevideo = $(".videoBox")[0];
  elevideo.addEventListener(
    "ended",
    function () {
      //结束
      // alert("播放结束");
      $("#dialog").show();
    },
    false
  );
});

$(".video-close").click(function () {
  $("#dialog").show();
  $(".videoBox").get(0).pause();
});

$("#btn").click(function () {
  linkTo("/doctor");
});
